package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userDishController")
@RequestMapping("/user/dish")
@Api("C类-菜品浏览接口")
@Slf4j
public class DishController {
    @Autowired
    private DishService dishService;
    @Autowired
    private RedisTemplate redisTemplate;


    /**
     * 根据分类id查询菜品及口味
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品及口味")
    @Cacheable(cacheNames = "dish_",key = "#categoryId")
    public Result<List<DishVO>> getDishByCategoryId(Long categoryId){
        log.info("根据分类id查询菜品及口味");

        Dish dish=Dish.builder()
                .status(StatusConstant.ENABLE)//查询起售的菜品与其口味
                .categoryId(categoryId)
                .build();

        List<DishVO>dishVoList = dishService.listWithFlavor(dish);


        return Result.success(dishVoList);
    }

}
